#include "problems/148.h"
#include "gtest/gtest.h"
#include <vector>

using namespace std;

TEST(TestProblemSolutions, TestProblem148_1)
{
    problem_148::Solution s;
    ListNode n1(4), n2(2), n3(1), n4(3);
    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;
    auto result = s.sortList(&n1);
    vector<int> ans{1, 2, 3, 4};
    for (auto n : ans)
    {
        ASSERT_NE(result, nullptr);
        ASSERT_EQ(result->val, n);
        result = result->next;
    }
}

TEST(TestProblemSolutions, TestProblem148_2)
{
    problem_148::Solution s;
    ListNode n1(4), n2(2);
    n1.next = &n2;
    auto result = s.sortList(&n1);
    vector<int> ans{2, 4};
    for (auto n : ans)
    {
        ASSERT_NE(result, nullptr);
        ASSERT_EQ(result->val, n);
        result = result->next;
    }
}

TEST(TestProblemSolutions, TestProblem148_3)
{
    problem_148::Solution s;
    ListNode n1(4), n2(2), n3(1), n4(3), n5(0), n6(-1);
    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;
    n4.next = &n5;
    n5.next = &n6;
    auto result = s.sortList(&n1);
    vector<int> ans{-1, 0, 1, 2, 3, 4};
    for (auto n : ans)
    {
        ASSERT_NE(result, nullptr);
        ASSERT_EQ(result->val, n);
        result = result->next;
    }
}